package com.wsoft.dc.controller;

import com.wsoft.dc.enums.ReadTypeEnum;
import com.wsoft.dc.query.read.BusinessReadQuery;
import com.wsoft.dc.query.read.ReadAllQuery;
import com.wsoft.dc.service.IDcBusinessReadService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 待办阅读状态 前端控制器
 * @author Z001
 * @since 2024年12月17日 16:17:47
 */
@RestController
@Tag(name = "已读/未读")
@RequestMapping("/dc/business")
public class DcBusinessReadController {

    @Resource
    private IDcBusinessReadService readService;


    @Operation(summary = "待办已读", description = "待办已读")
    @PostMapping("/read")
    public ResponseResult read(@RequestBody @Valid BusinessReadQuery query) {
        boolean b = readService.read(query, ReadTypeEnum.READ.getType());
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "一键已读", description = "一键已读")
    @PostMapping("/readAll")
    public ResponseResult readAll(@RequestBody ReadAllQuery query) {
        boolean b = readService.readAll(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }



    @Operation(summary = "待办未读", description = "待办未读")
    @PostMapping("/unread")
    public ResponseResult unread(@RequestBody @Valid BusinessReadQuery query) {
        boolean b = readService.read(query, ReadTypeEnum.UNREAD.getType());
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
}
